var app = getApp();
var util = require('../../../utils/util.js');
var ajax = require('../../../utils/ajax.js');
var common = require('../../../utils/common.js');
var PageBase = require('../../../common/PageBase.js');
var Pagination = require('../../../utils/pagination.js');

Page(common.extendPage(PageBase, {
  data: {
    winHei: 0,
    dataLoaded: false,
    userInfo: {},
    isLogin: false,
    currentTab: 1
  },

  onLoad: function () {
    common.initApp({
      extSuc: () => {
        //debugger;
      },
      loginSuc: () => {
        this.setData({
          isLogin: !!app.getUid(),
          userInfo: app.getUInfo()
        });
        this._getList({status: 1});
      }
    });
  },


  _getList(params) {
    var status = params.status;
    this._pagination = new Pagination({
      page: this,
      scope: 'pagination'
    }).init({
      rendData: (page, cb) => {

        ajax.G({
          url: 'm=plugins&c=groups&a=mygroups',
          data: {
            uid: app.getUid(),
            status: 0 || status,
            page,
            size: 20
          },
          success: (res) => {
            //debugger;
            var orderList = res.data.item;
            //var goodsList = this.data.goodsList || [];
            // var {
            //   goodsList = []
            //           } = res.data;
            var allList = this.data.orderList || [];
            //debugger;
            this.setData({
              dataLoaded: true,
              list: page == 1 ? orderList : allList.concat(orderList)
            });

            cb && cb(orderList.length);
          }
        });

      }
    });

  },

  /**
 * 事件切换tab
 */
  _tabSwitch: function (evt) {
    //debugger;
    var index = evt.currentTarget.dataset.current;
    var formId = evt.detail.formId;

    this._toTab(index);
    common.submitForm(formId);
  },

  _toTab: function (index, cb) {
    //debugger;
    this.setData({
      currentTab: index,
      list: [],
      page: 1
    });
    this._getList({
      status: index
    });
  },


}));